JavaBasic is a line command interpreter, loosely using the BASIC command set. The upper text box in the screen is the output area. The lower the input area. By default, the interpreter operates in the single line mode. Each command you enter will be executed immediately after the <ENTER> is pressed. Try to type following command:
a = "Hello "
? a, " World!", newline
"Hello World!" will be displayed in the output box. To run these two commands again, highlight both lines, and press <ENTER>.
You can defer the execution by press <CTRL>-<ENTER>, the cursor will move to the next line. After all commands are typed in, highlight all lines, and press <ENTER>.
Use command "Set Batch On" to switch to batch mode.
Use command "Set Batch Off"
to switch back to single line mode.
! NOTE ! Click anywhere outside the JavaBasic Applet after the first command is entered if you are using NetScape Navigator 2.0, and if the system seems hang up.
A command, or statement has following format:
[label ] [verb ] [attributes] [;remark]
Label is an optional integer constant. It does not require to be sequential or in any order. Warning! Duplication of label is not checked.
Verb specifies the command to be executed. If no verb is specified, command let is used.
Attributes is command dependent. There are explained in detail in section Command List
Remark is an optional comment to the command. It does not affect the command in any way.
Some quick notes on the JavaBasic Command:
See also Dim, Type Conversion, Command List
If you prefer to run a set of commands together, switch to batch mode. The other situation that you need batch mode is to use JavaBasic composite commands, such as for and if. For example:
sum = 0
FOR j = 1 TO 100
sum = sum + j
NEXT
It would be much easier to work in batch mode than single line mode.
Use Set Batch On to switch to batch mode. Here is a summary of batch mode:
Syntax:
clear [screen | name | data | command | all | variable-name-list]
See also Command List
Syntax:
data value-list
See also Command List, Input
Syntax:
dim varname [[ '['[size [, base] ] ']' ]...] [as type] [, varname [as type] ...]
dim a[2][3]
defines a two dimension array. If the size is omitted, the array will be treat as a free size array, i.e., its size will expanded automatically as necessary. For a given size array, out of range error occurs when index in not inside the range. Array base is always 1.
See also Command List
Syntax:
for control-variable = initial-expression to upper-bound-expression [step step-expression] do
command-list
next [control-variable]
See also Command List
Syntax:
gosub label
See also Command List, Goto, if...endif, for...next
Syntax:
goto label
label is an integer constant. Program control will unconditionally transfer to the statement specified by the label.
Note : if ... goto is not currently supported.
See also Command List, Gosub
Syntax
if Boolean-expression then
command-list-1
[ else
command-list-2]
endif
or
if Boolean-expression-1 then
command-list-1
else if Boolean-expression-2 then
command-list-2
[ else
command-list-3]
endif
See also Command List
Syntax:
input variable-name-list
See also Command List, Data
Syntax:
[ let] left-value = expression
See also Command List
Sorry, not implemented yet!
See also Command List
print expression-list
or
? expression-list
See also Command List
Syntax:
rem [any thing]
or
; [any thing]
rem this line doing nothing
; this line doing nothing either
j = j + 1 ; increase the counter
See also Command List
Syntax:
return
See also Command List, Gosub
Syntax:
run url-string
See also Command List
Syntax:
set batch on / off
See also Command List
| abs(double) | Returns the absolute double value of a. |
| acos(double) | Returns the arc cosine of a, in the range of 0.0 through Pi. |
| asin(double) | Returns the arc sine of a, in the range of -Pi/2 through Pi/2. |
| atan(double) | Returns the arc tangent of a, in the range of -Pi/2 through Pi/2. |
| cos(double) | Returns the trigonometric cosine of an angle. |
| exp(double) | Returns the exponential number e(2.718...) raised to the power of a. |
| log(double) | Returns the natural logarithm (base e) of a. |
| random(double) | Generates a random number between 0.0 and the given range. |
| sin(double) | Returns the trigonometric sine of an angle. |
| sqrt(double) | Returns the square root of a. |
| tan(double) | Returns the trigonometric tangent of an angle. |
Note, all constants can be overridden by assigning a new value to it, or declare a variable with the same name.
| newline | New line ("\n") |
| tab | Tab ("\t") |
| pi | Mathematical constant |
| e | Mathematical constant |
| true | Boolean constant |
| false | Boolean constant |
Types are automatically converted where necessary and possible. In the calculation, generally speaking, right operand is converted to the type of left operand. For example
? 1 + "23 " ;will produce 24
? "23" + 1 ;will produce "231"
? 1-"23" ;will produce -22
? "23"-1 ;will produce an error message.
Other rules in conversion:
Boolean type only can be converted to string type, with value "false" and "true"
String type can be converted to a Boolean value true of it is "true", otherwise always false.
Arithmetic Operator
+ (addition) - (subtraction) * (multiplication) / (division) ^ (power)
Logic Operator (List in order of preference)
> (greater than) >= (not less than) < (less than) >= (not greater than) = (equal) != (not equal) & (And) | (Or)